package filterCalc;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;

import project.LearningTool;
import project.V12;

/**
 * Filter Calculator tool.
 * 
 * This class contains all filters, and initiates them.
 * Holds a list of the filters, and shows the selected filter in its designated space
 * 
 * @author Sletten
 *
 */

public class FilterCalc extends LearningTool implements MouseListener, ActionListener
{
	private JLabel mHeader;
	
	private ArrayList<Filter> mFilter;
	private JList<Object> mFilterList;
	private Filter mActiveFilter;
	
	FilterCalc()
	{
		mFilter = new ArrayList<Filter>();
		mFilter.add(new FirstLPRC());
		//mFilter.add(new FirstLPRL());
		mFilter.add(new FirstHPRC());
		//mFilter.add(new FirstHPRL());
		mFilter.add(new SecondLP());
		//mFilter.add();
		//mFilter.add();
		
		for(int i = 0; i < mFilter.size(); i++)
		{
			mToolPanel.add(mFilter.get(i));
			mFilter.get(i).setVisible(false);
		}
		mActiveFilter = mFilter.get(0);
		
		mFilterList = new JList<Object>(mFilter.toArray());
		mFilterList.setBounds(10, 110, 130, 400);
		mFilterList.addMouseListener(this);
		mToolPanel.add(mFilterList);
		
		mToolPanel.setLayout(null);
		mToolPanel.setPreferredSize(new Dimension(800, 600));
		mToolPanel.setBackground(Color.GRAY);
		
		//Header
		mHeader = new JLabel();
		mHeader.setFont(new Font("Arial", Font.PLAIN, 45));
		mHeader.setText("Filter Calculator");
		//mHeader.setForeground(Color.WHITE);
		mHeader.setBounds(40, 15, 800, 70);
		mToolPanel.add(mHeader);
		
		//exit button
		JButton button = new JButton("Exit");
		button.setFont(new Font("Arial", Font.PLAIN, 15));
		button.setActionCommand("byebye");
		button.addActionListener(this);
		button.setBounds(20, 540, button.getPreferredSize().width, button.getPreferredSize().height);
		mToolPanel.add(button);
	}

	public void mouseClicked(MouseEvent e)
	{
		mActiveFilter.setVisible(false);
		mActiveFilter = mFilter.get(mFilterList.getSelectedIndex());
		mActiveFilter.setVisible(true);
		mHeader.setText(mActiveFilter.getFilterName());
	}
	public void mouseEntered(MouseEvent arg0){}
	public void mouseExited(MouseEvent arg0){}
	public void mousePressed(MouseEvent arg0){}
	public void mouseReleased(MouseEvent arg0){}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		if("byebye".equals(e.getActionCommand()))
		{
			V12.getInstance().stopTool();
		}
	}
}